//
//  BaseTabBar.m
//  db
//
//  Created by 张育铭 on 2019/7/29.
//  Copyright © 2019 赢辉网络科技有限公司. All rights reserved.
//

#import "BaseTabBar.h"
#import "ConversationViewController.h"
#import "InformationViewController.h"
#import "DiagnosisViewController.h"
#import "MarketViewController.h"
#import "MineViewController.h"

@interface BaseTabBar ()<UITabBarControllerDelegate>
@end

@implementation BaseTabBar

+ (void)initialize {
    [[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];
//    //设置为不透明
//    [UITabBar appearance].translucent = NO;
//    //字体移动
//    [UITabBarItem appearance].titlePositionAdjustment = UIOffsetMake(0, 1.5);
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10],NSForegroundColorAttributeName:[UIColor grayColor]} forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10],NSForegroundColorAttributeName:RGBCOLOR(119, 133, 251)} forState:UIControlStateSelected];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addChildViewControllerWithClassName:[ConversationViewController description]   imageName:@"tabbar_1" selectimageName:@"tabbar_1_s" title:@"健康信"];
    [self addChildViewControllerWithClassName:[InformationViewController description]  imageName:@"tabbar_2" selectimageName:@"tabbar_2_s" title:@"资讯"];
    [self addChildViewControllerWithClassName:[DiagnosisViewController description] imageName:@"tabbar_3"   selectimageName:@"tabbar_3_s"   title:@"问诊"];
    [self addChildViewControllerWithClassName:[MarketViewController description] imageName:@"tabbar_3"   selectimageName:@"tabbar_3_s"   title:@"市场"];
    [self addChildViewControllerWithClassName:[MineViewController description] imageName:@"tabbar_4" selectimageName:@"tabbar_4_s" title:@"我的"];
}

// 添加子控制
- (void)addChildViewControllerWithClassName:(NSString *)className
                                  imageName:(NSString *)imageName
                            selectimageName:(NSString *)selectimageName
                                      title:(NSString *)title {
    UIViewController *vc = [[NSClassFromString(className) alloc] init];
    //    vc.title = title;
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    nav.tabBarItem.title = title;
    nav.tabBarItem.image = [UIImage imageNamed:imageName];
    nav.tabBarItem.selectedImage = [[UIImage imageNamed:selectimageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [self addChildViewController:nav];
}

- (void)unreadMessageChange:(NSNotification *)notification {
    //    int totalUnreadCount = [[RCIMClient sharedRCIMClient] getTotalUnreadCount];
    //    NSString* unreadCountStr = [NSString stringWithFormat:@"%d",totalUnreadCount];
    //    if (totalUnreadCount>=99) {
    //        unreadCountStr = @"99+";
    //    }else if (totalUnreadCount <= 0){
    //        unreadCountStr = nil;
    //    }
    //    UITabBarItem *item = [self.tabBar.items objectAtIndex:0];
    //    item.badgeValue = unreadCountStr;
}

@end
